$(document).ready(function(){

    $("#right_arrow img").click(function(){
      $("#location_nav").scrollTo( '+=1280px', 1000, {axis:'x'} );
    });
    
    $("#left_arrow img").click(function(){
      $("#location_nav").scrollTo( '-=1280px', 1000, {axis:'x'} );
    });


  	$("ul.nav li").hover(
  		function(){ $("ul", this).fadeIn("fast"); }, 
  		function() { } 
  	);



    $.fn.hoverClass = function(c) {
    	return this.each(function(){
    		$(this).hover( 
    			function() { $(this).addClass(c);  },
    			function() { $(this).removeClass(c); }
    		);
    	});
    };	  


    if ($('.tabbed-page').length) {
    
    	var jqFirst = true;
    	
    	$(function () {
    		var tabContainers = $( '.tabbed-page' );
    		if ( !jqFirst ) {
    			tabContainers.hide();
    		}
    		    		
    		var menuItems = $( 'ul#content_tabs a' );
    		  menuItems.live("click", function(){
    			menuItems.removeClass( 'active' );
    			$(this).addClass( 'active' );
    			
    			var linkLocation = $(this).attr( 'href' );
    			var linkBits = linkLocation.split( '/' );
    			var divLocation = linkBits[ linkBits.length - 2 ];
    	
    			if ( !jqFirst ) {
    				$( '.tabbed-page' ).hide();
    				$( '#' + divLocation ).fadeIn( 300 );
    			} else {
    				jqFirst = false;
    			}
    			
    			return false;
    		});	
    		
    		menuItems.filter( ':first' ).click();	
    	});
    }


$("#overlay").click(function(){
      $("#map_overlay").toggle();
      return false;
    });


$.fn.reverseOrder = function() {
	return this.each(function() {
		$(this).prependTo( $(this).parent() );
	});
};

var directionSwitch = false;

$('#reverse_order').click(function(){
	$('#location_nav ul li').reverseOrder();

	if (directionSwitch) {
    $('#reverse_order').html("Belfast &raquo; Londonderry/Derry");
		directionSwitch = false;
	} else {
    $('#reverse_order').html("Londonderry/Derry &raquo; Belfast");
		directionSwitch = true;
	}
  
});	

if(window.location.hash) {
    var elem = $('#_' + window.location.hash.substring(1));
    var offset = elem.offset();
    $.scrollTo( offset.top, 1000, {axis:'y'} );
}

if (!$.cookie("visited_already")) {
  $("#help_section_standard").hide();   
  $("#help_section").show();
  $.cookie("visited_already", "true", { expires: 52 });
}


$('#close_help').click(function(){
  $('#help_section').fadeOut(300);
  $('#help_section_standard').fadeIn(300);  
});

$('#help_section_standard').click(function(){
  $('#help_section').fadeIn(300);
  $('#help_section_standard').fadeOut(300);  
});

});